package com.SmartWallet;

import android.app.Activity;
import android.app.ListActivity;
import 	android.content.Intent;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.*;

import com.SmartWallet.models.BudgetList;
import com.SmartWallet.models.ListEntry;

public class SmartWalletActivity extends ListActivity {
	public static HashMap<String,BudgetList> lists;
	public static BudgetList sanDiego, chicago, atlanta, philidelphia, girlfriend, groceries, misc;
	public static ArrayList<String> listNames;
	public static String selected;
    /** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	  super.onCreate(savedInstanceState);
	  lists = new HashMap<String,BudgetList>();
	  sanDiego = new BudgetList("San Diego", 350, 50);
	  chicago = new BudgetList("Chicago", 450, 100);
	  atlanta = new BudgetList("Atlanta", 350, 50);
	  philidelphia = new BudgetList("San Diego", 350, 50); 
	  girlfriend = new BudgetList("Girlfriend");
	  groceries = new BudgetList("Groceries",200, 20);
	  misc = new BudgetList("Misc.");
	  sanDiego.addEntry(new ListEntry("Chevy's",50,"Will be reimbursed", "food"));
	  lists.put(sanDiego.getName(), sanDiego);
	  lists.put(chicago.getName(), chicago);
	  lists.put(atlanta.getName(), atlanta);
	  lists.put(philidelphia.getName(), philidelphia);
	  lists.put(girlfriend.getName(), girlfriend);
	  lists.put(groceries.getName(), groceries);
	  lists.put(misc.getName(), misc);
	  
	  
	  
	  listNames = new ArrayList<String>();
	  listNames.add(sanDiego.getName());
	  listNames.add(chicago.getName());
	  listNames.add(atlanta.getName());
	  listNames.add(philidelphia.getName());
	  listNames.add(girlfriend.getName());
	  listNames.add(groceries.getName());
	  listNames.add(misc.getName());
	  
	  updateView();
	  
	  

	  
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.game_menu, menu);
	    return true;
	}
	
	public void updateView()
	{
		setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, listNames.toArray(new String[listNames.size()])));

		  ListView lv = getListView();
		  lv.setTextFilterEnabled(true);
		  lv.setOnItemClickListener(new OnItemClickListener() {
			    

				public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
						long arg3) {
					// TODO Auto-generated method stub
					/* Toast.makeText(getApplicationContext(), ((TextView) arg1).getText(),
					          Toast.LENGTH_SHORT).show();*/
					 
					 Intent intent = new Intent(SmartWalletActivity.this,ListViewActivity.class);
					 
					 selected = ((TextView) arg1).getText().toString();
					 
					
					
					

					

					//Start next activity
					SmartWalletActivity.this.startActivity(intent); 

					

					
					
				}
			  });
	}
	
	@Override
    protected void onStart() {
        super.onStart();
        // The activity is about to become visible.
    }
    @Override
    protected void onResume() {
        super.onResume();
        // The activity has become visible (it is now "resumed").
    }
    @Override
    protected void onPause() {
        super.onPause();
        // Another activity is taking focus (this activity is about to be "paused").
    }
    @Override
    protected void onStop() {
        super.onStop();
        // The activity is no longer visible (it is now "stopped")
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        // The activity is about to be destroyed.
    }
}